var app = getApp();
// import Dialog from "../../../dist/dialog/dialog";
Component({
  properties: {
    // 属性值可以在组件使用时指定
    datasource: {
      type: Array,
    },
    orderType: {
      type: String,
    },
    detailUrl: {
      type: String,
    },
    status: {
      type: Number,
    },
    consolidated:{
      type: Boolean,
      value: false
    },
    custom_receipt_confirmation_html:{
      type:String,
      value:""
    },
    member_type:{
      type:null,
      value:''
    },
    isOrder:{
      type:Boolean,
      value:false
    }
  },
  data: {
    language: "",
    regional: "请选择快递公司",
    dateshow_1: false,
    columns: [],
    checkList: [],
    options: [],
    //确认发货
    dialogVisible: false,
    expressName: "",
    numberName: "",
    addresseeInfo: {},
    showQrcode: false,
    qrcode_url: "",
    // 上拉菜单弹出层
    sendGoogsFail: {
      show: false,
      msg: "",
    },

    showID: "",
    jurisdiction_set: 0,

    showBarter: false,
    showBarter_value: null,
    filterExpressCompanys: [],
    inputExpressCompanyName: "",
    orderPayId: null,
    blindBoxInfo: {
      show: false,
      goods: [],
      //盲盒相关数据
    },
    refundShow: false, //退款原因
    refundText: "",

    custom_receipt_confirmation_show:false,   //自定义确认收货弹窗
    custom_receipt_confirmation_btn:{}, //自定义确认收货弹窗按钮
    custom_receipt_confirmation_item:{},//自定义确认收货弹窗item
    //S 申请存货弹窗
    inventoryApplyPopup: false, //存货申请弹窗
    inventoryApplyList: [], //仓库列表
    inventoryApplyRadio: null,
    //E 申请存货弹窗

    showKefu: false,

    overlayShow: false, //新盲盒商品 - 弹窗
    drawShow: false, //新盲盒商品-恭喜中奖 - 弹窗
    drawType: 1 , //新盲盒商品-中奖类型
    newBlindBoxData: {}, //新盲盒商品 - 开箱数据

  }, // 私有数据，可用于模板渲染

  lifetimes: {
    // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
    attached() {
      let language = wx.getStorageSync("langIndex");
      let yz_basic_info = wx.getStorageSync('yz_basic_info');
      this.setData({ 
        language: language.en,
        vip_show:yz_basic_info.globalParameter.vip_show?yz_basic_info.globalParameter.vip_show:false 
      });
      // this.getTemplate()
      // 在组件实例进入页面节点树时执行
    },
    moved() {},
    detached() {
      // 在组件实例被从页面节点树移除时执行
    },
  },
  pageLifetimes: {
    // 组件所在页面的生命周期函数
    show() {},
    hide() {},
    resize() {},
  },

  methods: {
    toUrl(e) {
      let _data = e.currentTarget.dataset || {};
      this.wxRouterLink(_data);
    },
    wxRouterLink(_data) {
      let _Param = "";
      const { url, ...otherParam } = _data;
      Object.keys(otherParam).forEach(function (key) {
        if (otherParam[key] !== "") _Param += key + "=" + otherParam[key] + "&";
      });
      if (url === "") return;
      wx.navigateTo({
        url: url + "?" + _Param.slice(0, -1),
      });
    },
    filterExpressCompany(event) {
      let input = event.detail;
      const columns = this.data.columns;
      this.setData({
        filterExpressCompanys: columns.filter((val) => {
          return val.indexOf(input) !== -1;
        }),
        inputExpressCompanyName: input,
      });
    },
    toStore(e) {
      let order = e.currentTarget.dataset.order;
      if (order.plugin_id == 92) {
        wx.navigateTo({
          url: "/packageA/member/supplier/SupplierShop/SupplierShop?id=" + order.id + "&fromOrder=1",
        });
      } else if (order.plugin_id == 31 || order.plugin_id == 32) {
        wx.navigateTo({
          url: "/packageC/o2o/o2oStore/o2oStore?store_id=" + order.id + "&fromOrder=1",
        });
      } else if (order.plugin_id == 54 && order.has_one_team_member.store_id) {
        wx.navigateTo({
          url: "/packageC/o2o/o2oStore/o2oStore?store_id=" + order.has_one_team_member.store_id + "&fromHome=1",
        });
      } else if (order.plugin_id == 0) {
        wx.reLaunch({
          url: "/packageG/index/index",
        });
      }
    },
    showMore(e) {
      let order_sn = e.currentTarget.dataset.order.order_sn;
      this.setData({
        showID: this.data.showID == order_sn ? "" : order_sn,
      });
    },
    //获取模板id
    getTemplate(order, btn) {
      let urlStr = app.getNetAddresss("member.member.getMiniTemplateCorrespond");
      let that = this;
      app._getNetWork({
        url: urlStr,
        data: {
          small_type: 2,
        },
        success: function (resdata) {
          var res = resdata.data;
          if (res.result == 1) {
            let array = [];
            for (let i = 0; i < res.data.length; i++) {
              array.push(res.data[i].template_id);
            }
            that.setData({
              TemplateArray: array,
            });
            wx.requestSubscribeMessage({
              tmplIds: that.data.TemplateArray,
              success(res) {
                that._toRefund(order, btn);
              },
              fail() {
                that._toRefund(order, btn);
              },
            });
          } else {
            wx.showToast({
              title: res.msg,
              icon: "none",
              duration: 1500,
            });
          }
        },
        fail: function (res) {
          console.log(res);
        },
      });
    },
    multiplePayChange(event) {
      this.setData({
        checkList: event.detail,
      });
      this.triggerEvent("MultiplePayNotification", this.data.checkList);
    },
    //跳转到对应的订单详情
    goOrderdetail(e) {
      let orderType = this.data.orderType;
      let orderid = e.currentTarget.dataset.orderid;
      let _url = "/packageA/member/orderdetail/orderdetail?order_id=" + orderid + "&orderType=" + orderType;
      if(this.data.member_type == 2 || this.data.member_type == 4){
        url = _url + "&debt_shop_member_type=" + this.data.member_type
      }
      wx.navigateTo({
        url: _url
      });
    },
    //根据按钮值判断用途
    operation(e) {
      let btn = e.currentTarget.dataset.item;
      let order = e.currentTarget.dataset.order;
      let orderidx = e.currentTarget.dataset.orderidx;
      this.setData({
        orderPayId: order.id,
      });

      if (!btn.api && btn.value != 41) {
        if (btn.value == "expediting_delivery") {
          wx.showToast({
            icon: "none",
            title: "已提醒过商家",
            duration: 1000,
          });
        } else {
          //接口没有返回按钮点击请求的地址
          wx.showToast({
            icon: "none",
            title: "缺失必要参数",
            duration: 1000,
          });
        }
        return;
      }

      if (btn.value == 8 || btn.value == "snatch_regiment_express") {
        //查看物流
        this._checklogistics(order, btn);
      } else if (btn.value == 12) {
        //删除订单
        this._deleteOrder(order, btn, orderidx);
      } else if (btn.value == 51) {
        //聚合cps
        if (order.plugin_id == "71") {
          wx.navigateTo({
            url: "/packageH/cpsPwd/cpsPwd?id=" + order.id,
          });
        }
      } else if (btn.value == 10) {
        //评价订单
        this._comment(order, btn);
      } else if (btn.value == 1 || btn.value == "snatch_regiment_pay") {
        //订单支付
        this._toPay(order, btn);
      } else if (btn.value == 13 || btn.value == "snatch_regiment_refund" || btn.value == '54') {
        //退款
        this.getTemplate(order, btn);
      } else if (btn.value == 9) {
        //取消订单
        this._cancleOrder(order, btn, orderidx);
      } else if (btn.value == 5) {
        //确认订单
        this._confirmOrder(order, btn);
      } else if (btn.value == 18) {
        //退款中
        this._toRefundDetail(order, btn);
      } else if (btn.value == "cashierPay") {
        //订单已付款
        this._cashPayOrder(order, btn);
      } else if (btn.value == "verification_code") {
        this._verification(order, btn);
      } else if (btn.value == 20) {
        this._verificationCash(order, btn);
      } else if (btn.value == 21) {
        //跳到OrderRecord
        wx.navigateTo({
          url: "/packageD/member/myOrder/order_record/order_record?order_id=" + item.id,
        });
      } else if (btn.value == 22) {
        // 确认支付
        this.publicMessage(btn, order, '支付');
      } else if (btn.value == 101) {
        let _url = "/packageE/pickUpCard/pickUpCardReimburse/pickUpCardReimburse?orderid=" + order.id;
        if(this.data.orderType == "picking-card-one" || order.plugin_id == 95) _url = _url + '&plugin=one';
        wx.navigateTo({
          url: _url
        });
      } else if (btn.value == "coupon") {
        wx.navigateTo({
          url: "/packageD/coupon_share/coupon_share?orderid=" + order.id,
        });
      } else if (btn.value == 23 || btn.value == 60) {
        // 确认发货
        if (order.dispatch_type_id == 3) {
          this.sendGoogs();
        } else {
          this._getCompany();
          this.setData({
            dialogVisible: true,
          });
        }

        this.triggerEvent("stoprefresh", true);
        this.setData({
          expressName: "",
          numberName: "",
        });
      } else if (btn.value == 24 || btn.value == 61) {
        //取消发货
        this.publicMessage(btn, order, '取消发货');
      } else if (btn.value == 25) {
        //确认收货
        this.publicMessage(btn, order, '收货');
      } else if (btn.value == 26) {
        //关闭订单
        this.publicMessage(order, btn, "关闭");
      } else if (btn.value == 30) {
        //退款关闭订单
        this.publicMessage(order, btn, "退款关闭订单");
      } else if (btn.value == 27) {
        this._evaluate(order, btn);
      } else if (btn.value == 28) {
        //卡密
        this._truckList(btn, order);
      } else if (btn.value == 41) {
        //398售后
        // wx.navigateTo({
        //   url: btn.api,
        // });
        this.getKefu(order.has_many_order_goods);
      } else if (btn.value == 50) {
        //查看发票
        this._checkInvoice(btn, order);
      } else if (btn.value == 11) {
        //酒店确认下单
        this.publicMessage(order, btn, "下单");
      } else if (btn.value == "lease_toy_refund") {
        this.publicMessage(btn, order, "申请归还");
      } else if (btn.value == "lease_toy_apply_adopt" || btn.value == 'yz_lease_apply_adopt') {
        if(btn.value == 'yz_lease_apply_adopt'){
          wx.navigateTo({
            url: "/packageB/member/OrderReturn/OrderReturn?id=" + order.id + '&type=yz_lease_apply_adopt',
          });
          return
        }
        wx.navigateTo({
          url: "/packageB/member/OrderReturn/OrderReturn?id=" + order.id,
        });
      } else if (btn.value == "lease_toy_return_info" || btn.value == "yz_lease_return_info") {
        console.log("归还详情");
        if(btn.value == 'yz_lease_return_info'){
          wx.navigateTo({
            url: "/packageA/others/order_ruturn_info/order_ruturn_info?id=" + order.id + '&type=yz_lease_return_info',
          });
          return
        }
        wx.navigateTo({
          url: "/packageA/others/order_ruturn_info/order_ruturn_info?id=" + order.id,
        });
      } else if (btn.value == "yz_lease_refund") {
        // 供应商租赁中台商品 申请归还
        this.publicMessage(btn, order, "申请归还");
      } else if (btn.value == "package_deliver" || btn.value == "package_delivery_confirm_code" || btn.value == "store_package_deliver" || btn.value == "reserve_simple") {
        this.getQrImg(btn, order);
      } else if (btn.value == "expediting_delivery") {
        this.publicMessage(btn, order, "提醒商家发货");
      } else if (btn.value == "snatch_regiment_barter") {
        // 抢团易货兑换
        this.setData({
          showBarter: true,
          showBarter_value: order.barter,
        });
      } else if(btn.value == 53){
        this.getBlindBoxGoods(order.id);
      } else if(btn.value == 56){
        wx.navigateTo({
          url:"/packageH/project_verification/MyProject/MyProject"
        });
      } else if (btn.value == "close_reason") {
        this.setData({
          refundShow: true,
          refundText: order.close_reason
        });
      } else if (btn.value == 140){
        wx.navigateTo({
          url:"/packageI/brand_resources/cardVoucherInfo/cardVoucherInfo?id="+order.id
        });
      } else if(btn.value == "city_delivery_detail"){
        wx.navigateTo({
          url:"/packageA/member/order/orderLogisticsDetails/orderLogisticsDetails?id="+order.id
        });
      } else if (btn.value == "inventory_apply") {
        this.getWarehouseList_CH(); //获取仓库列表(申请存货)
      } else if (btn.value == "new_blind_box_unpacking") { // 新盲盒商品-去开箱
        wx.navigateTo({
          url:"/packageF/new_blind_box/blindBox/index?order_id="+order.id
        });
      } else if (btn.value == "new_blind_box_goods") { // 新盲盒商品-未点发货或兑换
        this.setData({
          overlayShow: true,
          newBlindBoxData: {
            api: btn.api,
            order_id: order.id
          }
        })
      } else if (btn.value == "new_blind_box_exchange_order") { // 新盲盒商品-兑换积分
        this.setData({
          drawShow: true,
          drawType: 2,
          newBlindBoxData: {
            api: btn.api,
            order_id: order.id
          }
        })
      } else if (btn.value == "new_blind_box_sub_order") { // 新盲盒商品-已兑换
        this.setData({
          drawShow: true,
          drawType: 1,
          newBlindBoxData: {
            api: btn.api,
            order_id: order.id
          }
        })
      } else if (btn.value == 'coffee_store_code_list'){
        wx.navigateTo({
          url: '../../../packageJ/coffee_machine/coffee_machine_verification/coffee_machine_verification?order_id=' + order.id,
        })
      } else {
        this.publicMessage(btn, order, btn.name);
      }
    },
    getBlindBoxGoods(id){
      let that = this;
      let urlStr = app.getNetAddresss('plugin.blind-box.api.index.blind-box-goods');
      urlStr += '&order_id=' + this.data.orderPayId;
      app._getNetWork({
        url: urlStr,
        success: function(resdata) {
          var res = resdata.data;
          if (res.result == 1) {
            that.setData({
              ['blindBoxInfo.show']:true,
              ['blindBoxInfo.goods']:res.data.order
            });
          } else {
            wx.showToast({
              icon: 'none',
              title: res.msg,
              duration: 1200
            });
          }
        },
        fail: function(res) {
          console.log(res);
        }
      });
    },
    blindBoxInfoTap(){
      this.setData({
        ['blindBoxInfo.show']:false,
      });
    },
    goOrderList(item){
      let id = item.currentTarget.dataset.item.id;
      let orderType = this.data.orderType;
      wx.navigateTo({
        url: '/packageA/member/orderdetail/orderdetail?order_id=' + id + '&orderType=' + orderType
      });
    },
    confirmBarter() {
      let urlStr = app.getNetAddresss("plugin.snatch-regiment.api.order.barter");
      urlStr += "&order_id=" + this.data.orderPayId;
      app._getNetWork({
        url: urlStr,
        success: function (resdata) {
          var res = resdata.data;
          if (res.result == 1) {
            wx.showToast({
              title: `易货兑换成功`,
              icon: "success",
              duration: 1500,
              success: function () {},
            });
            that.getdata();
          } else {
            wx.showToast({
              icon: "none",
              title: res.msg,
              duration: 1200,
            });
          }
        },
        fail: function (res) {
          console.log(res);
        },
      });
    },
    cancelBarter() {
      this.setData({
        showBarter: false,
        showBarter_value: null,
      });
    },
    // 自提点确认核销
    getQrImg(btn, order) {
      let urlStr = app.getNetAddresss(btn.api);
      if (btn.value == "package_deliver"||btn.value == "store_package_deliver") {
        urlStr += "&order_id=" + order.id;
      } else if(btn.value == "package_delivery_confirm_code"){
        urlStr += "&order_id=" + order.id;
      } else if(btn.value == "reserve_simple"){
        urlStr += "&id=" + order.id;
      } else {
        urlStr += "&order_pay_id=" + order.id;
      }
      app._getNetWork({
        url: urlStr,
        success: (resdata) => {
          var res = resdata.data;
          if (res.result == 1) {
            this.setData({
              showQrcode: true,
              qrcode_url: res.data.qr_code_url,
            });
          } else {
            wx.showToast({
              icon: "none",
              title: res.msg,
              duration: 1000,
            });
          }
        },
        fail: function (res) {
          console.log(res);
        },
      });
    },

    publicMessage(btn, order, text) {
      let that = this;
      if (!btn.api) {
        return;
      }
      wx.showModal({
        title: "提示",
        content: `确定${text}?`,
        success(res) {
          if (res.confirm) {
            let urlStr = "";
            urlStr += app.getNetAddresss(btn.api);
            urlStr += "&order_id=" + that.data.orderPayId;
            app._getNetWork({
              url: urlStr,
              success: function (res) {
                var resdata = res.data;
                if (resdata.result == 1) {
                  that.triggerEvent("ConfrimOrderNotification", "pay");
                  if(btn.value == 'inventory_cancel'){
                    wx.showModal({
                      content:'申请成功,请到待发货列表查询此订单',
                    });
                  } else if(btn.value == "yz_lease_refund") {
                    app.tips("申请归还成功")
                  } else{
                    wx.showToast({
                      icon: "success",
                      title: `${text}成功`,
                      duration: 1000,
                    });
                  }
                } else {
                  wx.showToast({
                    icon: "none",
                    title: resdata.msg,
                    duration: 1000,
                  });
                }
              },
              fail: function (resdata) {
                console.log(resdata);
              },
            });
          }
        },
      });
    },
    onClose() {
      this.setData({
        showQrcode: false,
      });
    },
    //查看物流
    _checklogistics(item, btn) {
      //logistics
      if (item.is_all_send_goods == 0) {
        wx.navigateTo({
          url: "/packageA/member/order/logistics/logistics?id=" + item.id + "&api=" + btn.api,
        });
      } else {
        wx.navigateTo({
          url: "/packageE/multiplePackages/multiplePackages?id=" + item.id + "&api=" + btn.api,
        });
      }
    },
    //删除订单
    _deleteOrder(item, btn, orderidx) {
      let that = this;
      wx.showModal({
        title: "提示",
        content: "确定删除此订单?",
        success(res) {
          if (res.confirm) {
            //删除当前选中的地址
            let datasource = that.data.datasource;
            datasource.splice(orderidx, 1);
            that.setData({
              datasource: datasource,
            });
            that._sentRequest(btn.api, "&order_id=" + item.id, false);
          }
        },
      });
    },
    _sentRequest(action, params, isIndicator) {
      let urlStr = app.getNetAddresss(action);
      urlStr += params;
      app._getNetWork({
        url: urlStr,
        success: function (resdata) {
          var res = resdata.data;
          if (res.result == 1) {
            wx.showToast({
              title: res.msg,
              icon: "none",
              duration: 1500,
              success: function () {
                setTimeout(function () {
                  //要延时执行的代码
                  wx.navigateBack({
                    delta: 1,
                  });
                }, 1500); //延迟时间
              },
            });
          } else {
            wx.showToast({
              icon: "none",
              title: res.msg,
              duration: 1000,
            });
          }
        },
        fail: function (res) {
          console.log(res);
        },
      });
    },
    //评价订单
    _comment(item, btn) {
      wx.navigateTo({
        url: "/packageB/comment/comment?order=" + JSON.stringify(item ? item : {}),
      });
      // 跳到评价订单
      //comment
    },
    _toPay(item, btn) {
      if(item.plugin_id == '107'){
        wx.navigateTo({
          url: '/packageD/buy/orderPay/orderPay?order_id=' + item.id + '&status=1'+ '&api=' + btn.api+'&name=bilndBox'
        });
        return;
      }
      //status-2合并支付 type-1订单支付
      wx.navigateTo({
        url: "/packageD/buy/orderPay/orderPay?order_id=" + item.id + "&status=1" + "&api=" + btn.api,
      });
    },
    //退款中
    _toRefundDetail(item, btn) {
      if(item.plugin_id == 154){
        wx.navigateTo({
          url: `/packageD/member/myOrder/Aftersales/Aftersales?refund_id=${item.travel_around_refund?.id}&pluginid=${item.plugin_id}`,
        });
      } else {
        //aftersales
        wx.navigateTo({
          url: "/packageD/member/myOrder/Aftersales/Aftersales?refund_id=" + item.refund_id,
        });
      }
      
    },
    //退款
    _toRefund(item, btn) {
      let _url = '/packageD/member/myOrder/refund/refund';
      if(item.plugin_id == '107'){
        _url =  _url + "?order_id=" + item.id + "&type=1"+'&value='+btn.value
      }
      if(item.plugin_id == '154'){
        _url =  _url + `?order_id=${item.travel_around_order?.order_id}&type=4&value=${btn.value}&pluginid=${item.plugin_id}`
      }
      if (btn.value == "snatch_regiment_refund") {
        //抢团
        _url =  _url + "?order_id=" + item.id + "&type=3"
      } else {
        _url =  _url + "?order_id=" + item.id + "&type=1"
      }
      wx.navigateTo({ url: _url });
    },
    //取消订单
    _cancleOrder(item, btn, orderidx) {
      var that = this;
      wx.showModal({
        title: "提示",
        content: "确定取消此订单?",
        success(res) {
          if (res.confirm) {
            //取消当前选中的地址
            let datasource = that.data.datasource;
            datasource.splice(orderidx, 1);
            that.setData({
              datasource: datasource,
            });
            that._sentRequest(btn.api, "&order_id=" + item.id, false);
          }
        },
      });
    },
    //确认收货
    _confirmOrder(item, btn) {     
      if((item.plugin_id==0 || item.plugin_id==44) && this.data.custom_receipt_confirmation_html!==''){
        this.setData({
          custom_receipt_confirmation_btn:btn,
          custom_receipt_confirmation_item:item,
          custom_receipt_confirmation_show:true
        });
        return;
      }
      wx.showModal({
        title: "提示",
        content: "您确定收到货物?",
        success:(resqu)=> {
          if (resqu.confirm) {
            this._confirmOrder_request(item,btn);
          }
        },
      });
    },
    CustomReceiptConfirmationSend(){
      this._confirmOrder_request(this.data.custom_receipt_confirmation_item,this.data.custom_receipt_confirmation_btn);
    },
    _confirmOrder_request(item,btn){
      let urlStr = app.getNetAddresss(btn.api);
      urlStr += "&order_id=" + item.id;
      app._getNetWork({
        url: urlStr,
        success: (resdata) => {
          var res = resdata.data;
          if (res.result == 1) {
            this.triggerEvent("ConfrimOrderNotification", "pay");
            app.tips(res.msg);
          } else {
            app.tips(res.msg);
          }
        },
        fail: (res) => {
          console.log(res);
        },
      });
    },
    _cashPayOrder(item, btn) {
      let that = this;
      wx.showModal({
        title: "提示",
        content: "确定此订单已付款?",
        success(res) {
          if (res.confirm) {
            that._sentRequest(btn.api, "&order_id=" + item.id + "&order_pay_id=" + that.data.order_pay_id, false);
          }
        },
      });
    },
    _verification(item, btn) {
      //订单核销
      //orderVerification
      wx.navigateTo({
        url: "/packageD/member/myOrder/orderVerification/orderVerification?order_id=" + item.id + "&api=" + btn.api,
      });
    },
    _verificationCash(item, btn) {
      let that = this;
      wx.showModal({
        title: "提示",
        content: "确定此订单已付款?",
        success(res) {
          if (res.confirm) {
            that._sentRequest(btn.api, "&order_id=" + item.id + "&order_pay_id=" + that.data.order_pay_id, false);
          }
        },
      });
    },

    //获取快递公司
    _getCompany() {
      let that = this;
      let urlStr = "";
      if (that.data.orderType == "supplier") {
        urlStr += app.getNetAddresss("plugin.supplier.frontend.order.express-company");
      } else if (that.data.orderType == "subsidiary") {
        urlStr += app.getNetAddresss("plugin.subsidiary.frontend.order.express-company");
      } else if (that.data.orderType == "storeMang") {
        urlStr += app.getNetAddresss("plugin.shop-assistant.frontend.order.expressCompanies");
      } else {
        urlStr += app.getNetAddresss("plugin.store-cashier.frontend.store.center.sendOrder");
      }
      urlStr += "&order_id=" + that.data.orderPayId;
      app._getNetWork({
        url: urlStr,
        success: function (resdata) {
          var res = resdata.data;
          if (res.result == 1) {
            that.setData({
              options: res.data.express_companies,
            });
            var arrayOfSquares = that.data.options.map(function (item) {
              return item.name;
            });
            if (!app._isTextEmpty(res.data.jurisdiction_set)) {
              that.setData({
                jurisdiction_set: res.data.jurisdiction_set,
              });
            }
            that.setData({
              columns: arrayOfSquares,
              addresseeInfo: res.data.address,
            });
            if(that.data.regional && that.data.regional!=='请选择快递公司'){
              res.data.express_companies.forEach(item=>{
                if(item.name == that.data.regional){
                  let obj =  {
                    value:item.value,
                    name:item.name
                  }
                  that.setData({expressName:obj})
                }
              })
            }
          }
        },
        fail: function (res) {
          console.log(res);
        },
      });
    },

 
    // 评价
    _evaluate(order, btn) {
      //抢单评价
      //DeliveryEvaluate
      wx.navigateTo({
        url: "/packageD/member/myOrder/DeliveryEvaluate/DeliveryEvaluate?order_id=" + order.order_id + "&api=" + btn.api + "&name=distributor",
      });
    },
    //卡密
    _truckList(btn, order) {
      //TruckList
      wx.navigateTo({
        url: "/packageD/member/myOrder/truckList/truckList?order_id=" + order.id,
      });
    },
    //查看发票
    _checkInvoice(btn, order) {
      //Invoice
      wx.navigateTo({
        url: "/packageD/member/myOrder/invoice/invoice?order_id=" + order.id,
      });
    },
    //快递单号输入值绑定
    numberNamebtn(e) {
      let val = e.detail.value;
      this.setData({
        numberName: val,
      });
    },
    //确认发货
    sendGoogs(event) {
      if (!event || event.detail === "confirm") {
        let that = this;
        // 发货失败上拉弹出菜单函数
        const sendGoogsFail = (msg) => {
          this.setData({
            sendGoogsFail: {
              show: true,
              msg,
            },
            dialogVisible: false,
          });
        };
        let json = {
          order_id: that.data.orderPayId,
          express_code: that.data.expressName.value,
          express_company_name: that.data.expressName.name,
          express_sn: that.data.numberName,
        };
        let urlStr = "";
        if (this.data.orderType == "supplier") {
          urlStr += app.getNetAddresss("plugin.supplier.frontend.order.send");
        } else if (this.data.orderType == "subsidiary") {
          urlStr = app.getNetAddresss("plugin.subsidiary.frontend.order.send");
        } else if (this.data.orderType == "auction" || this.data.orderType=='storeMang') {
          urlStr = app.getNetAddresss("plugin.auction.api.order-operation.send");
          if(this.data.orderType=='storeMang'){
            urlStr += app.getNetAddresss("plugin.shop-assistant.frontend.order.send");
          }
        } else {
          urlStr = app.getNetAddresss("plugin.store-cashier.frontend.store.center.order-operation.send");
        }

        app._postNetWork({
          url: urlStr,
          showToastIn: false,
          data: json,
          success: function (resdata) {
            var res = resdata.data;
            if (res.result == 1) {
              that.setData({
                dialogVisible: false,
              });
              that.triggerEvent("stoprefresh", false);
              that.triggerEvent("ConfrimOrderNotification", "pay");
              wx.showToast({
                icon: "success",
                title: "发货成功",
                duration: 1000,
              });
            } else {
              sendGoogsFail(res.msg);
            }
          },
          fail: function (res) {},
        });
      } else {
        this.setData({
          dialogVisible: false,
        });
        this.triggerEvent("stoprefresh", false);
      }
    },
    // 关闭上拉弹出
    colseSendGoogsFailPopup() {
      this.setData({
        "sendGoogsFail.show": false,
      });
    },
    //快递选择
    seleRegional: function () {
      this.setData({
        dateshow_1: true,
      });
    },
    onCancelbtn: function () {
      this.setData({
        dateshow_1: false,
        inputExpressCompanyName: "",
        filterExpressCompanys: [],
      });
    },
    onConfirmbtn: function (e) {
      let index = e.detail.index;
      let val = e.detail.value;
      let array = this.data.options.filter((item) => {
        return item.name.indexOf(this.data.inputExpressCompanyName) !== -1;
      });
      this.setData({
        dateshow_1: false,
        regional: val,
        expressName: array[index],
        inputExpressCompanyName: "",
        filterExpressCompanys: [],
      });
    },
 
    copyorderbtn(e) {
      let copydata = e.currentTarget.dataset.copydata;
      wx.setClipboardData({
        data: copydata ? copydata : "",
        success(res) {
          wx.showToast({
            icon: "none",
            title: "复制成功",
            duration: 1000,
          });
        },
      });
    },
    onCloseRefundShow(){
      this.setData({
        refundShow: false
      });
    },

    // 评价，追评，查看评价按钮
    evaluateOpration(e) {
      let btn = e.target.dataset.btn;
      let item = e.target.dataset.goods;
      let order_id = e.target.dataset.order.id;
      //value-0评价 value-1追加评价 value-2查看评价详情
      if (btn.value == 0) {
        wx.navigateTo({
          url: '/packageD/member/evaluate/evaluate?order_id=' + order_id + '&id=' + item.id
        });
      } else if (btn.value == 1) {
        wx.navigateTo({
          url: '/packageD/member/addevaluate/addevaluate?order_id=' + order_id + '&item=' + JSON.stringify(item)
        });
      } else if (btn.value == 2) {
        let options = "?order_id=" + order_id;
        options = options + '&goods_id=' + item.has_one_comment.goods_id;
        options = options + '&comment_id=' + item.has_one_comment.id;
        options = options + '&order_goods_id=' + item.id;
        wx.navigateTo({
          url: '/packageD/member/CommentDetails/CommentDetails' + options
        });
      }
    },

    onChangeInventoryApplyRadio(event){
      this.setData({
        inventoryApplyRadio: event.detail,
      });
    },
    getWarehouseList_CH() {
      let urlStr = app.getNetAddresss("plugin.order-inventory.frontend.index.warehouse-list");
      app._postNetWork({
        url: urlStr,
        data: {},
        success: (resdata) => {
          let res = resdata.data;
          if (res.result == 1) {
            this.setData({
              inventoryApplyList: res.data.list, //仓库列表
              inventoryApplyRadio: res.data.list[0].id,
              inventoryApplyPopup: true //存货申请弹窗
            })
          } else {
            app.tips(res.msg)
          }
        },
        fail: (res) => {
          console.log(res);
        },
      });
    },
    confirmInventoryApply() {
      let urlStr = app.getNetAddresss("plugin.order-inventory.frontend.index.inventory-apply");
      app._postNetWork({
        url: urlStr,
        data: { warehouse_id: this.data.inventoryApplyRadio, order_id: this.data.orderPayId },
        success: (resdata) => {
          let res = resdata.data;
          app.tips(res.msg)
          if (res.result == 1) {
            this.triggerEvent("ConfrimOrderNotification", "pay");
          }
        },
        fail: (res) => {
          console.log(res);
        },
      });
    },
    // 获取客服
  getKefu(good) {
    let goods_id = "";

    if (good.length > 0) {
      goods_id = good[0].goods_id;
    }
    let urlStr = app.getNetAddresss("goods.customer-service.index");
    app._postNetWork({
      url: urlStr,
      data: {
        goods_id: goods_id,
      },
      success: (resdata) => {
        var res = resdata.data;
        if (res.result == 1) {
          this.setData({
            customer_open:res.data.customer_open == 0?false:true,
            showKefu: true,
            cservice: res.data.cservice,
            service_QRcode: res.data.service_QRcode,
            service_mobile: res.data.service_mobile,
          });
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },
  //关闭新盲盒商品 - 弹窗
  issueGoodsClose() {
    this.setData({
      overlayShow: false
    })
  },
  drawGoodsClose() {
    this.setData({
      drawShow: false
    })
  }
  },
});
